package exercise17;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import chapter15.FigurePanel;

public class Exercise17_2 extends JFrame{
	
	private FigurePanel figurePanel = new FigurePanel();
	private JRadioButton jrbLine = new JRadioButton("Line");
	private JRadioButton jrbRect = new JRadioButton("Rectangle");
	private JRadioButton jrbOval = new JRadioButton("Oval");
	private JCheckBox jcbFilled = new JCheckBox("Filled");
	
	public Exercise17_2(){
		setLayout(new BorderLayout(5, 5));
		Border lineborder = new LineBorder(Color.BLACK, 1);
		JPanel jpBtns = new JPanel();
		jpBtns.add(jrbLine);
		jpBtns.add(jrbRect);
		jpBtns.add(jrbOval);
		jpBtns.add(jcbFilled);
		jpBtns.setBorder(lineborder);
		figurePanel.setBorder(lineborder);
		
		ButtonGroup group = new ButtonGroup();
		group.add(jrbLine);
		group.add(jrbRect);
		group.add(jrbOval);
		
		add(figurePanel, BorderLayout.CENTER);
		add(jpBtns, BorderLayout.SOUTH);
		
		jrbLine.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				figurePanel.setType(FigurePanel.LINE);
			}
		});
		
		jrbRect.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				figurePanel.setType(FigurePanel.RECTANGLE);
			}
		});
		
		jrbOval.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				figurePanel.setType(FigurePanel.OVAL);
			}
		});
		
		jcbFilled.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				figurePanel.setFilled(jcbFilled.isSelected());
				
			}
		});
		
		
	}

	public static void main(String[] args) {
		Exercise17_2 frame = new Exercise17_2();
		frame.setTitle("Exercise17_2");
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);

	}

}
